<template>
	<view>
		<view class="head">
			<image src="../../static/images/arrow_left.png" mode=""></image>
			<view class="">采购入库</view>
			<view class="f32">全选</view>
		</view>
		
		<view class="name f30 "> 供应商：{{arry.supplier_name}}</view>
		
		<view v-for="(item, index) in storeList" :key="index">
			<view class="number">
				<view class="numberLeft">订单号：{{ item.order_no }}</view>
				<view class="numberRight">{{ item.create_time | birtime }}</view>
			</view>
			<view v-for="(val, sub) in item.goods_list" :key="sub">
				<view class="photo">
					<view class="left">
						<view class="photoHead"><dimg :src="val.cover"></dimg></view>
						<view class="photoCenter">
							<view class="photoTop">{{ val.title }}</view>
							<view class="photobot">未入库数 : {{ total(val) }}</view>
						</view>
					</view>
					<view class="photoRight">
						<!-- 	<view class="photoTop">
					<image :src="ImageUrl" mode="" @click="selectedCheck"></image>
					全部退货
				</view> -->
						<view class="photobot" @click="ShowBox">
							{{ showZhan }}
							<image :src="zhanImage" mode=""></image>
						</view>
					</view>
				</view>
				<view class="box" v-show="Showbox">
					<view class="boxTop">
						<view class="boxLeft">规格(库存）</view>
						<view class="boxCenter">未入库数</view>
						<view class="boxRight">入库数</view>
					</view>
					<view class="boxbot" v-for="(spec, i) in val.product_list" :key="i">
						<view class="boxLeft">
							<block v-for="(specitem, dropIndex) in spec.spec_data" :key="dropIndex">
								{{ specitem }}
								<block v-if="dropIndex < spec.spec_data.length - 1">/</block>
							</block>
							({{ spec.store_num }})
						</view>
						<view class="boxCenter">{{ spec.convert_num }}</view>
						<view class="boxRight"><stepper size="small" :min="0" :max="spec.convert_num" :childindex="i" @change="changeNum"></stepper></view>
					</view>
				</view>
			</view>
		</view>

		<view class="but">
			<view class="butLeft">本次发货总数：0</view>
			<button type="primary" @tap="define">确定入库</button>
		</view>
	</view>
</template>

<script>
import stepper from '../../components/stepper/stepper.vue';
export default {
	components: {
		stepper
	},
	data() {
		return {
			ImageUrl: '../../static/client/butt1.png', //图片地址
			Check: false, //选中
			Showbox: false,
			showZhan: '展开',
			zhanImage: '../../static/slice/1.png',
			supplierId: '',
			orderId: '',
			productList: [],
			storeList: [],
			goodList: [],
			info:[],
			arry:{},
			supplierData:[]
		};
	},
	onLoad(option) {
		this.supplierId = option.supplierId;
		this.orderId = option.orderId;
		this.getWaitInStore();
		this.getOrderInfo()
		

	},

	methods: {
		selectedCheck() {
			if (this.Check) {
				(this.ImageUrl = '../../static/client/butt1.png'), (this.Check = false);
			} else {
				(this.ImageUrl = '../../static/client/butt2.png'), (this.Check = true);
				// console.log(this.Check);
			}
		},
		ShowBox() {
			if (this.Showbox) {
				this.showZhan = '展开';
				this.zhanImage = '../../static/slice/1.png';
				this.Showbox = false;
			} else {
				this.showZhan = '收起';
				this.zhanImage = '../../static/images/arrow_ondown.png';
				this.Showbox = true;
			}
		},
		total(item) {
			let c = 0;
			item.product_list.forEach(item => {
				c = +item.convert_num + c;
			});
			return c;
		},
		
		//采购详情
		getOrderInfo() {
			let that = this;
			that.$ajax('api/v1.supplier/orderInfo', {
				order_id: that.orderId
			})
				.then(res => {
					if ((res.code = 1)) {
						that.arry = res.result;
					
					}
				})
				.catch(res => {
					that.$sToast(res.message);
				});
		},
		getInfo(){
			let that=this;
			that.$ajax('api/v1.supplier/index',{
				}).then(res=>{
					if(res.code==1){
						that.info=res.result
						console.log(that.info)
					}
				}).catch(res=>{
					that.$sToast(res.message)
				})
		},
		
		//入库前调接口

		getWaitInStore() {
			let that = this;
			that.$ajax('api/v1.supplier/waitInStore', {
				supplier_id: that.supplierId,
				order_id: that.orderId
			})
				.then(res => {
					if (res.code == 1) {
						that.storeList = res.result.list;
						that.productList = res.result.list[0].goods_list[0];
						that.goodList=res.result.list[0].goods_list[0].product_list
				
					}
				})
				.catch(res => {
					that.$sToast(res.message);
				});
		},
		//数量累加
		changeNum(e) {
			this.productList.product_list[+e.childindex].operate_num = +e.num;
			//console.log(this.productList)
			this.goodList.forEach(item=>{
				delete item.order_id;
				delete item.goods_id;
				delete item.spec_data;
				delete item.owe_num;
				delete item.store_num;
				delete item.unit_id;
				delete item.unit_name;
				delete item.convert_num;
			})
			
			
		},
		//确认入库
		
		define() {
			
		   this.goodList.forEach(item=>{
		   	delete item.order_id;
		   	delete item.goods_id;
		   	delete item.spec_data;
		   	delete item.owe_num;
		   	delete item.store_num;
		   	delete item.unit_id;
		   	delete item.unit_name;
		   	delete item.convert_num;
		   })
			this.supplierData=[{
			customer_id: this.arry.supplier_id,
			delivery_name: '',
			delivery_no: '',
			operate_id: 0,
			operate_type: 0,
			order_id: this.orderId,
			product_list: JSON.stringify(this.goodList),
			remark: '发货',
			send_sms: 0	
			}]
			console.log(this.supplierData)
			uni.request({
				url: getApp().globalData.apiurl + '/api/v1.supplier/goInStore', //仅为示例，并非真实接口地址。
				data: {
					0: JSON.stringify(this.supplierData)
				},
				method: 'POST',
				header: {
					'content-type': 'application/json',
					token: uni.getStorageSync('userinfo').token
				},
				success: res => {
					// this.getWaitInStore()
					// uni.showToast({
					// 	title: '入库成功',
					// 	icon: 'none'
					// });
			     console.log(res.message);
					setTimeout(function() {
						uni.navigateTo({
							url: './PO'
						});
					}, 1500);
				}
			});
		}
	
		
		
		
}
};
</script>

<style lang="less">
page {
	background-color: #f7f4f8;
}
.head {
	height: 88rpx;
	line-height: 88rpx;
	background-color: #249af6;
	color: #ffffff;
	display: flex;
	justify-content: space-between;
	padding: 0 30rpx;
	font-size: 36rpx;
	font-family: PingFang SC;
	font-weight: 500;
	image {
		width: 22rpx;
		height: 39rpx;
		margin-top: 25rpx;
	}
}
.name{
	padding: 30rpx 30rpx 0 30rpx;
	color: #249AF6;
}
.number {
	height: 103rpx;
	line-height: 103rpx;
	padding-left: 30rpx;
	padding-right: 30rpx;
	margin-top: 30rpx;
	background-color: #ffffff;
	display: flex;
	justify-content: space-between;
	font-size: 30rpx;
	font-family: PingFang SC;
	font-weight: 500;
	color: rgba(51, 51, 51, 1);
	border-bottom: 2rpx solid #eeeeee;
	.numberRight {
		font-size: 30rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #666666;
	}
}
.photo {
	height: 164rpx;
	background-color: #ffffff;
	padding-left: 30rpx;
	padding-right: 30rpx;
	padding-top: 30rpx;
	box-sizing: border-box;
	display: flex;
	flex-direction: row;
	justify-content: space-between;
	.left {
		display: flex;
		flex-direction: row;
	}
	.photoHead {
		height: 100rpx;
		width: 100rpx;
		// background-color: blue;
		border-radius: 50%;
		overflow: hidden;

		image {
			width: 100rpx;
			height: 100rpx;
		}
	}
	.photoCenter {
		margin-left: 36rpx;
		font-size: 30rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: rgba(51, 51, 51, 1);
		line-height: 36rpx;
	}
	.photobot {
		font-size: 28rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: rgba(102, 102, 102, 1);
		line-height: 88rpx;
	}
	.photoRight {
		margin-left: 180rpx;
		.photoTop {
			font-size: 30rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: rgba(102, 102, 102, 1);
			image {
				width: 32rpx;
				height: 32rpx;
				position: relative;
				left: -20rpx;
				top: 5rpx;
			}
		}
		.photobot {
			text-align: right;
			color: #249af6;
			image {
				width: 17rpx;
				height: 10rpx;
				margin-left: 20rpx;
			}
		}
	}
}
.box {
	height: 212rpx;
	.boxTop {
		height: 100rpx;
		line-height: 100rpx;
		background-color: #eeeeee;
		display: flex;
		justify-content: space-around;
		font-size: 32rpx;
		font-family: PingFang SC;
		font-weight: 500;
		border-bottom: 2rpx solid #cccccc;
	}
	.boxbot {
		height: 100rpx;
		line-height: 100rpx;
		display: flex;
		background-color: #eeeeee;
		color: #666666;
		font-size: 32rpx;
		font-family: PingFang SC;
		font-weight: 500;
		justify-content: space-around;

		.boxCenter {
			position: relative;
			left: 30rpx;
		}
	}
}
.but {
	width: 100%;
	height: 110rpx;
	position: fixed;
	bottom: 0;
	background-color: #ffffff;
	display: flex;
	box-sizing: border-box;
	font-size: 30rpx;
	font-family: PingFang SC;
	font-weight: 500;
	line-height: 110rpx;
	padding-left: 29rpx;
	.butLeft {
		width: 495rpx;
		background-color: #ffffff;
	}
	button {
		line-height: 110rpx;
		flex: 1;
		font-size: 30rpx;
	}
}
</style>
